package com.example.apollotogit.utils;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class JsonFile {
    /**
     * 读取json文件并且转换成字符串
     *
     * @return strbuffer 文件内容字符串
     * @throws IOException 文件IO流报错
     */
    public String readJsonData() throws IOException {
        // 读取文件数据
        String pactFile = "X:\\json\\apollotogit.json";
        StringBuilder strbuffer = new StringBuilder();
        File myFile = new File(pactFile);
        if (!myFile.exists()) {
            System.err.println("Can't Find " + pactFile);
        }
        try {
            FileInputStream fis = new FileInputStream(pactFile);
            InputStreamReader inputStreamReader = new InputStreamReader(fis, StandardCharsets.UTF_8);
            BufferedReader in = new BufferedReader(inputStreamReader);

            String str;
            while ((str = in.readLine()) != null) {
                strbuffer.append(str);
            }
            in.close();
        } catch (IOException e) {
            e.getStackTrace();
        }
        return strbuffer.toString();
    }
}
